home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
lisp
/
kcl
/
kcl.lha
/
c
/
num_pred.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-06-04
|
3KB
|
215 lines
/*
(c) Copyright Taiichi Yuasa and Masami Hagiya, 1984. All rights reserved.
Copying of this file is authorized to users who have executed the true and
proper "License Agreement for Kyoto Common LISP" with SIGLISP.
*/
/*
Predicates on numbers
*/
#include "include.h"
#include "num_include.h"
number_zerop(x)
object x;
{
switch (type_of(x)) {
case t_fixnum:
if (fix(x) == 0)
return(1);
else
return(0);
case t_bignum:
case t_ratio:
return(0);
case t_shortfloat:
if (sf(x) == 0.0)
return(1);
else
return(0);
case t_longfloat:
if (lf(x) == 0.0)
return(1);
else
return(0);
case t_complex:
return(number_zerop(x->cmp.cmp_real) &&
number_zerop(x->cmp.cmp_imag));
default:
FEwrong_type_argument(Snumber, x);
}
}
number_plusp(x)
object x;
{
switch (type_of(x)) {
case t_fixnum:
if (fix(x) > 0)
return(1);
else
return(0);
case t_bignum:
if (big_sign((struct bignum *)x) > 0)
return(1);
else
return(0);
case t_ratio:
if (number_plusp(x->rat.rat_num))
return(1);
else
return(0);
case t_shortfloat:
if (sf(x) > 0.0)
return(1);
else
return(0);
case t_longfloat:
if (lf(x) > 0.0)
return(1);
else
return(0);
default:
FEwrong_type_argument(TSor_rational_float);
}
}
number_minusp(x)
object x;
{
switch (type_of(x)) {
case t_fixnum:
if (fix(x) < 0)
return(1);
else
return(0);
case t_bignum:
if (big_sign((struct bignum *)x) < 0)
return(1);
else
return(0);
case t_ratio:
if (number_minusp(x->rat.rat_num))
return(1);
else
return(0);
case t_shortfloat:
if (sf(x) < 0.0)
return(1);
else
return(0);
case t_longfloat:
if (lf(x) < 0.0)
return(1);
else
return(0);
default:
FEwrong_type_argument(TSor_rational_float);
}
}
number_oddp(x)
object x;
{
int i;
if (type_of(x) == t_fixnum)
i = fix(x);
else if (type_of(x) == t_bignum)
i = x->big.big_car;
else
FEwrong_type_argument(Sinteger, x);
return(i & 1);
}
number_evenp(x)
object x;
{
int i;
if (type_of(x) == t_fixnum)
i = fix(x);
else if (type_of(x) == t_bignum)
i = x->big.big_car;
else
FEwrong_type_argument(Sinteger, x);
return(~i & 1);
}
Lzerop()
{
check_arg(1);
check_type_number(&vs_base[0]);
if (number_zerop(vs_base[0]))
vs_base[0] = Ct;
else
vs_base[0] = Cnil;
}
Lplusp()
{
check_arg(1);
check_type_or_rational_float(&vs_base[0]);
if (number_plusp(vs_base[0]))
vs_base[0] = Ct;
else
vs_base[0] = Cnil;
}
Lminusp()
{
check_arg(1);
check_type_or_rational_float(&vs_base[0]);
if (number_minusp(vs_base[0]))
vs_base[0] = Ct;
else
vs_base[0] = Cnil;
}
Loddp()
{
check_arg(1);
check_type_integer(&vs_base[0]);
if (number_oddp(vs_base[0]))
vs_base[0] = Ct;
else
vs_base[0] = Cnil;
}
Levenp()
{
check_arg(1);
check_type_integer(&vs_base[0]);
if (number_evenp(vs_base[0]))
vs_base[0] = Ct;
else
vs_base[0] = Cnil;
}
init_num_pred()
{
make_function("ZEROP", Lzerop);
make_function("PLUSP", Lplusp);
make_function("MINUSP", Lminusp);
make_function("ODDP", Loddp);
make_function("EVENP", Levenp);
}